import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '@/layout/Layout.vue'
import Login from '@/views/login'


Vue.use(VueRouter)

//隐藏原地跳转错误
const VueRouterPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(to) {
  return VueRouterPush.call(this, to).catch(err => err)
}

const routes = [
 
   
]
// 静态路由
export const constantRoutes=[
  {
    path:'/',
    redirect:'/home',
    hidden:true
  },
  {
    path:'/login',
    component:Login,
    hidden:true
  },
  // 首页
  {
    path:'/home',
    component:Layout,
    meta:{path:'/home',title:'首页', icon: 'home'},
    children:[
      {
        path:'',
        component:()=>import('@/views/home')
      }
    ]
  },
]
// 动态路由（异步路由)需要划分权限的路由
export const asyncRoutes=[
  
  /* 订单管理 */
  {
    path:'/order',
    meta:{path:'/order',title:'订单管理',roles:['super'],icon: 'order'},
    component:Layout,
    children:[
      {
        path:'',
        component:()=>import('@/views/order')
      },
      {
        hidden:true,
        path:'/order/order-detail',
        component:()=>import('@/views/order/order-detail')
      },
      {
        hidden:true,
        path:`/order/order-edit/:id`,
        component:()=>import('@/views/order/order-edit')
      },

    ]
  },
    /* 商品管理 */
  {
    path:'/goods',
    component:Layout,
    meta:{path:'/goods',title:'商品管理',icon: 'goods'},
    redirect:'/goods/goods-list',
    children:[
      {
        path:'/goods/goods-list',
        meta:{path:'/goods/goods-list',title:'商品列表',},
        component:()=>import('@/views/goods/goods-list')
      },
      {
        path:'/goods/goods-add',
        meta:{path:'/goods/goods-add',title:'商品添加',roles:['super']},
        component:()=>import('@/views/goods/goods-add')
      },
      {
        path:'/goods/goods-cate',
        meta:{path:'/goods/goods-cate',title:'商品分类'},
        component:()=>import('@/views/goods/goods-cate')
      },

    ]
  },
  // 店铺管理
  {
    path:'/shop',
    component:Layout,
    meta:{path:'/shop',title:'店铺管理',roles:['super'], icon: 'shop'},
    redirect:'/shop',
    children:[
      {
        path:'',
        component:()=>import('@/views/shop')
      },
      

    ]
  },
    /* 账号管理 */
  {
    path:'/account',
    component:Layout,
    meta:{path:'/account',title:'账号管理', icon: 'user'},
    redirect:'/account/account-list',
    children:[
      {
        path:'/account/account-list',
        meta:{path:'/account/account-list',title:'账号列表',roles:['super']},
        component:()=>import('@/views/account/account-list')
      },
      {
        path:'/account/account-add',
        meta:{path:'/account/account-add',title:'账号添加',roles:['super']},
        component:()=>import('@/views/account/account-add')
      },
      {
        path:'/account/password',
        meta: {path: '/account/password', title: '修改密码'},
        component:()=>import('@/views/account/password-modify')
      },
      {
        path:'/account/account-person',
        meta: {path: '/account/account-person', title: '个人中心'},
        component:()=>import('@/views/account/account-person')
      },

    ]
  },
    /* 销售统计 */
    {
      path:'/total',
      component:Layout,
      meta: {path: '/total', title: '销售统计',roles:['super'],icon: 'total'},
      redirect:'/total/total-goods',
      children:[
        {
          path:'/total/total-goods',
          meta: {path: '/total/total-goods', title: '商品统计'},
          component:()=>import('@/views/total/total-goods')
        },
        {
          path:'/total/total-order',
          meta: {path: '/total/total-order', title: '订单统计'},
          component:()=>import('@/views/total/total-order.vue')
        },
      
  
      ]
    },
]
// 错误路由 404
export const errorRoutes=[
   // 404
   {
    path:'*',
    redirect:'/404'
  },
  {
    path:'/404',
    component:()=>import('@/views/404/error.vue')
  }

]

const router = new VueRouter({
  routes:constantRoutes
})

export default router


